# from dataclasses import dataclass
import numpy as np
import math
# @dataclass
# class PosData:
#     time: np.ndarray
#     lat: np.ndarray
#     lon: np.ndarray
#     h: np.ndarray

# 读取oritation 
def read_data_gy(path_filename):
    ori = []

    with open(path_filename, "r") as file:  # 打开文件
        lines = file.readlines()
    file.close()

    for line in lines:
        line_data = line.split()
        ori.append(line_data[0])

    return ori

# 读取轨迹数据的时间和经纬高
def read_data_pos(path_filename):
    # pos =  np.array([])
    pos = []

    with open(path_filename, "r") as file:  # 打开文件
        lines = file.readlines()
    file.close()

    for line in lines:
        line_data = line.split()
        # print(line_data)
        time = float(line_data[0])
        lat = float(line_data[2])
        lon = float(line_data[3])
        h = float(line_data[4])
        ori = float(line_data[7])
        pos_delta = float(line_data[13])
        tmp = [time, lat, lon, h, ori, pos_delta]
        
        pos.append(tmp)

    return np.array(pos)
# 读取地磁数据
def read_data_mag(path_filename):
    # pos =  np.array([])
    mag = []

    with open(path_filename, "r") as file:  # 打开文件
        lines = file.readlines()
    file.close()

    for line in lines:
        line_data = line.split()
        # print(line_data)
        time = float(line_data[3].split(',')[1])
        # print(time)
        magx = float(line_data[0])
        magy = float(line_data[1])
        magz = float(line_data[2])
        mag_xyz = math.sqrt(magx**2 + magy**2 + magz**2)
        # mag_xyz = math.sqrt(magx**2 + magy**2)

        tmp = [time, magx, magy, magz, mag_xyz]
        
        mag.append(tmp)

    return np.array(mag)

# 读取轨迹数据的时间和经纬高
def read_data_groundtruth(path_filename):
    # pos =  np.array([])
    pos = []

    with open(path_filename, "r") as file:  # 打开文件
        lines = file.readlines()
    file.close()

    for line in lines[20:-6]:
        line_data = line.split()
        # print(line_data)
        time = float(line_data[1])
        lat = float(line_data[2])
        lon = float(line_data[3])
        h = float(line_data[4])
        heading = float(line_data[8])
        Pitch = float(line_data[9])
        Roll = float(line_data[10])
        # pos_delta = float(line_data[13])
        tmp = [time, lat, lon, h, heading, Pitch, Roll]
        
        pos.append(tmp)

    return np.array(pos)